package cn.java79.quiz.web;

import cn.java79.quiz.entity.Practise;
import cn.java79.quiz.entity.Questions;
import cn.java79.quiz.entity.User;
import cn.java79.quiz.pojo.AjaxResult;
import cn.java79.quiz.pojo.Section;
import cn.java79.quiz.service.*;
import cn.java79.quiz.util.StrUtil;
import com.alibaba.fastjson.JSON;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Properties;
import java.util.Random;

@WebServlet("*.role")
public class RoleServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        String path = req.getServletPath();
        path = path.substring(1, path.length() - 5);
        try {
            Method m = this.getClass().getDeclaredMethod(path, HttpServletResponse.class, HttpServletRequest.class);
            m.invoke(this, resp, req);
        } catch (Exception e) {
            e.printStackTrace();
            resp.sendError(501, "服务器出现了错误" + e);
        }
    }



    //显示知识点
    public void search(HttpServletResponse resp, HttpServletRequest req) throws ServletException, IOException {
       String rolename=req.getParameter("rolename");
       int pageNo=StrUtil.toInt(req.getParameter("pageNo"),1);
        req.setAttribute("p",RoleService.ME.search(rolename,pageNo));
        req.setAttribute("rolename",rolename);
        req.getRequestDispatcher("/WEB-INF/jsps/roles.jsp").forward(req, resp);
    }


}